import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/widgets/app/app_input.dart';
import 'package:bxultimate/widgets/app/app_title.dart';
import 'package:bxultimate/widgets/app/app_upload.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:bxultimate/widgets/mk_scroll_view.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart' hide TDInput, TDInputType;

import 'controller.dart';

class OrganizationCreatePage extends StatefulWidget {
  const OrganizationCreatePage({Key? key}) : super(key: key);

  @override
  State<OrganizationCreatePage> createState() => _OrganizationCreatePageState();
}

class _OrganizationCreatePageState extends State<OrganizationCreatePage> {
  final controller = Get.find<OrganizationCreateController>();
  final state = Get.find<OrganizationCreateController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: TDNavBar(
          backgroundColor: Colors.transparent,
          title: '创建队伍',
        ),
        body: MkScrollView(
          bottomButton: TDButton(
            text: '创建',
            shape: TDButtonShape.circle,
            height: 48,
            onTap: controller.createOrg,
            isBlock: true,
            theme: TDButtonTheme.primary,
          ),
          children: [
            Gaps.vGap16,
            Obx(()=>TDCell(
              style: TDCellStyle(
                  backgroundColor: Colors.transparent,
                  requiredStyle: TextStyle(
                    color: TDTheme.of(context).errorColor6,
                    fontSize: TDTheme.of(context).fontBodyLarge?.size ?? 16,
                    height: TDTheme.of(context).fontBodyLarge?.height ?? 24,
                    fontWeight: FontWeight.w400,
                  )),
              arrow: true,
              required: true,
              noteWidget: _noteWidget('${state.typeName}'),
              title: '队伍类型',
              onClick: controller.typeSelect,
            )),
            Obx(()=>Visibility(
              visible: state.showLevel,
                child: TDCell(
                  style: TDCellStyle(
                      backgroundColor: Colors.transparent,
                      requiredStyle: TextStyle(
                        color: TDTheme.of(context).errorColor6,
                        fontSize: TDTheme.of(context).fontBodyLarge?.size ?? 16,
                        height: TDTheme.of(context).fontBodyLarge?.height ?? 24,
                        fontWeight: FontWeight.w400,
                      )),
                  arrow: true,
                  required: true,
                  noteWidget: _noteWidget('${state.levelName}'),
                  title: '队伍级别',
                  onClick: controller.levelSelect,
                ))),
            TDInput(
              controller: controller.nameController,
              leftLabel: '队伍名称',
              required: true,
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            Obx(() => TDCell(
                  style: TDCellStyle(
                      backgroundColor: Colors.transparent,
                      requiredStyle: TextStyle(
                        color: TDTheme.of(context).errorColor6,
                        fontSize: TDTheme.of(context).fontBodyLarge?.size ?? 16,
                        height: TDTheme.of(context).fontBodyLarge?.height ?? 24,
                        fontWeight: FontWeight.w400,
                      )),
                  arrow: true,
                  required: true,
                  noteWidget: state.addressName != ''
                      ? _noteWidget('')
                      : _noteWidget('请选择地理位置'),
                  description: state.addressName == '' ? '' : state.addressName,
                  title: '地理位置',
                  onClick: controller.addressSelect,
                )),

            TDInput(
              controller: controller.reasonController,
              maxLength: 200,
              leftLabel: '创建理由',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
              hintText: '请输入创建理由',
              inputType: TextInputType.phone,
            ),

            // 上传图片或者商品
            Padding(
              padding: EdgeInsets.all(AppTheme.iDefaultPadding + 4),
              child: Row(
                children: [
                  Text(
                    '队伍图标',
                    style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
                  ),
                ],
              ),
            ),
            Obx(() => Padding(
                padding: EdgeInsets.only(left: AppTheme.iDefaultPadding),
                child: AppUpload(
                  maxCount: 1,
                  imgList: state.imgList,
                  videoList: state.videoList,
                )))
          ],
        ),
      ),
    );
  }

  _noteWidget(text) {
    return Text(
      text,
      style: TextStyle(fontSize: 16),
    );
  }

  @override
  void dispose() {
    Get.delete<OrganizationCreateController>();
    super.dispose();
  }
}
